<template>
	<view class="list-page">
		<u-navbar leftIconColor="#000" :autoBack="true" :placeholder="true" bgColor="rgba(255,255,255,0.0)">
			<view slot="center" class="nav-title">
				抢购
			</view>
		</u-navbar>
		<view v-if="list.length > 0">
			<view class="goods">
				<view class="goods-item" v-for="(item,index) in list" :key="index">
					<image :src="item.logo" mode=""></image>
					<view class="goods-bottom">
						<view class="purchase_no">
							{{item.purchase_no}}
						</view>
						<view class="goods-info">
							<view class="goods-price">
								￥{{item.price}}
							</view>
						</view>
						<view class="goods-btn">
							<u-button color="#FD5674" @click="goqiang(item)" shape="circle" type="primary"
								text="立即抢购"></u-button>
						</view>
					</view>
				</view>
			</view>
			<view class="btn-box">
				<view class="btn" @click="gopage(1)">上一页</view>
				<view class="btn" @click="gopage(2)">下一页</view>
			</view>
		</view>
		<u-empty v-else mode="list" icon="../../../static/home/none.png" :marginTop="100" text="订单列表为空">
		</u-empty>
		<u-popup :show="show" @close="close" mode="center" round="20">
			<view class="pop">
				<view class="pop-title">
					<view></view>
					<view>
						抢购成功
					</view>
					<u-icon name="close" color="#ffffff" size="22" @click="close"></u-icon>
				</view>
				<view class="pop-content">
					<view class="pop-info">
						<image :src="info.logo" mode=""></image>
						<view class="info-right">
							<view class="purchase_no">
								{{info.purchase_no}}
							</view>
							<view class="info-num">
								￥<text>{{info.price}}</text>
							</view>
						</view>
					</view>
					<view class="pop-btn">
						<u-button type="primary" text="确定" color="#FD5674" shape="circle" @click="navto"
							size="large"></u-button>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				page: 1,
				status: 'loadmore',
				show: false,
				info: {}
			}
		},
		onShow() {
			this.page = 1
			this.postassets()
		},
		methods: {
			gopage(e) {
				if (e == 1) {
					if (this.page == 1) {
						uni.showToast({
							title: '没有上一页了！',
							icon: 'none'
						})
					} else {
						this.page = this.page - 1
						this.postassets()
					}
				} else {
					if (this.list.length < 10) {
						uni.showToast({
							title: '没有下一页了！',
							icon: 'none'
						})
					} else {
						this.page = this.page + 1
						this.postassets()
					}
				}
			},
			navto() {
				this.show = false
			},
			close() {
				this.show = false
			},
			goqiang(item) {
				uni.showLoading({
					mask: true
				})
				let params = {
					order_id: item.id
				}
				this.$Request({
					method: 'POST',
					url: '/api/Trade/userAdopt',
					data: params,
					ismsg: true,
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						this.info = item
						this.show = true
						this.page = 1
						this.postassets()
					}
				})
			},
			postassets() {
				let params = {
					page: this.page,
				}
				this.$Request({
					method: 'POST',
					url: '/api/Trade/tradelist',
					data: params,
					ismsg: false,
				}).then(res => {
					if (res.code == 1) {
						if (res.data.list.length < 10) {
							this.status = 'nomore';
						}
						this.list = res.data.list
						uni.pageScrollTo({
							scrollTop: 0,
							duration: 300 // 滚动动画时长
						})
					}
				})

			}
		}
	}
</script>

<style scoped lang="scss">
	.list-page {
		background-image: url('../../../static/home/home-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 340rpx;
		padding: 30rpx;

		.pop {
			width: 600rpx;
			border-radius: 30rpx;

			.pop-title {
				padding: 20rpx 30rpx;
				background-color: #FD5674;
				display: flex;
				justify-content: space-between;
				font-size: 32rpx;
				color: #fff;
				font-weight: bold;
				border-top-right-radius: 30rpx;
				border-top-left-radius: 30rpx;
			}

			.pop-content {
				padding: 30rpx;

				.pop-info {
					display: flex;
					align-items: center;
					margin-top: 10rpx;

					image {
						width: 128rpx;
						height: 128rpx;
						border-radius: 20rpx;
					}

					.info-right {
						margin-left: 20rpx;
						.purchase_no {
							font-size: 26rpx;
							color: #333333;
						}
						.info-title {
							font-size: 32rpx;
							color: #333333;
						}

						.info-text {
							font-size: 26rpx;
							color: #999999;
						}

						.info-num {
							font-size: 26rpx;
							color: #FF4E4E;

							text {
								font-size: 32rpx;
								font-weight: bold;
							}
						}
					}
				}

				.pop-btn {
					margin-top: 30rpx;
				}
			}
		}

		.btn-box {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.btn {
				width: 48%;
				background-color: #FF4E4E;
				text-align: center;
				padding: 20rpx 0;
				border-radius: 50rpx;
				color: #fff;
			}
		}

		.goods {
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;

			.goods-item {
				width: 48%;
				margin-bottom: 30rpx;
				box-shadow: 0rpx 3rpx 32rpx 1rpx rgba(0, 0, 0, 0.08);
				background-color: #eee;
				border-radius: 30rpx;

				image {
					width: 100%;
					height: 320rpx;
					border-top-right-radius: 30rpx;
					border-top-left-radius: 30rpx;
				}

				.goods-bottom {
					padding: 20rpx;
					background-color: #fff;
					border-bottom-left-radius: 30rpx;
					border-bottom-right-radius: 30rpx;

					.goods-title {
						font-size: 26rpx;
						color: #000000;
						font-weight: 600;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}

					.purchase_no {
						font-size: 26rpx;
					}

					.goods-info {
						display: flex;
						justify-content: space-between;
						margin-top: 10rpx;

						.goods-price {
							font-size: 28rpx;
							color: #FF4E4E;
							font-weight: bold;

							text {
								font-weight: normal;
								color: #cccccc;
								text-decoration: line-through;
								margin-left: 10rpx;
							}
						}
					}

					.goods-btn {
						margin-top: 30rpx;
					}
				}
			}
		}
	}
</style>